import requests
from bs4 import BeautifulSoup

# 基本Url
base_url = 'http://top.baidu.com/'
hot_type = '0'

parameters = {'type': hot_type}

# 获取 JSON 数据
def get_hot_words():
    try:
        r = requests.get(base_url, params=parameters)
        r.encoding='gbk'
        my_bs4=BeautifulSoup(r.text,'lxml')
        news_html_list=my_bs4.select('.tab-box > ul > li')
        news=[]
        for news_html in news_html_list:
            news.append(news_html.find('a').get_text())
        return news
    except Exception as e:
        return []
if __name__ == '__main__':
    print(get_hot_words())
    pass
